package com.bicon.botu.mall.base.controller;

import com.bicon.botu.mall.base.common.MallHomePageConstants;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.core.base.repository.redis.RedisHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统设置后台接口管理
 *
 * @author 张凡
 * @date 2017/8/30 16:21.
 */
@RestController
@CrossOrigin
@RequestMapping("/V1.0.0/homePage/SystemSetting")
public class SystemSettingController extends BaseController {
    @Autowired
    RedisHandler redisHandler;

    /**
     * 后台新增或修改搜索关键字
     *
     * @param searchKey
     * @return
     */
    @RequestMapping(value = "/addSearchKey", method = RequestMethod.POST)
    public BaseResult add(String searchKey) {
        redisHandler.getLocalRedisTemplate().cacheStringValue(MallHomePageConstants.SETTING_KEY, MallHomePageConstants.SEARCH_KEY, searchKey);
        return sendResult(200, "新增搜索关键字成功");
    }

    /**
     * 后台获取搜索关键字
     *
     * @return
     */
    @RequestMapping(value = "/getSearchKey", method = RequestMethod.POST)
    public BaseResult getSearchKey() {
        String searchKey = redisHandler.getLocalRedisTemplate().getStringValue(MallHomePageConstants.SETTING_KEY, MallHomePageConstants.SEARCH_KEY);
        return sendResult(200, "获取搜索关键字成功", searchKey);
    }
}
